//
//  WYCategoryCell.m
//  Boss
//
//  Created by admin on 2018/6/23.
//  Copyright © 2018年 admin. All rights reserved.
//

#import "WYCategoryCell.h"
#import "WYSubCategoryCell.h"
@interface WYCategoryCell()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (strong, nonatomic) IBOutlet UICollectionView *collectionView;


@end
@implementation WYCategoryCell

- (void)awakeFromNib {
    [super awakeFromNib];
    [self setUpUI];
}

-(void)setUpUI
{
  
    
    UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc]init];
    layout.itemSize=CGSizeMake((kScreenWidth-50)/4, (kScreenWidth-50)/4);
    //横向最小距离
    layout.minimumInteritemSpacing=10.0f;
    layout.minimumLineSpacing=10.0f;
    //cell距离上  左  下 右 的距离
    layout.sectionInset=UIEdgeInsetsMake(10, 10, 10, 10);
    [layout setScrollDirection:UICollectionViewScrollDirectionVertical];
    [self.collectionView setCollectionViewLayout:layout];
    
    [self.collectionView registerNib:[UINib nibWithNibName:@"WYSubCategoryCell" bundle:nil] forCellWithReuseIdentifier:@"WYSubCategoryCell"];
    self.collectionView.dataSource=self;
    self.collectionView.delegate = self;
}

-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 8;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    WYSubCategoryCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"WYSubCategoryCell" forIndexPath:indexPath];
    if (!cell) {
        cell = [[NSBundle mainBundle]loadNibNamed:@"WYSubCategoryCell" owner:nil options:nil].firstObject;
    }
    return cell;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    if ([self.delegate respondsToSelector:@selector(didSelectCollectionViewcellWithIndex:)]) {
        [self.delegate didSelectCollectionViewcellWithIndex:indexPath];
    }
    
    
}



@end
